<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "goods_gallery".
 *
 * @property integer $id
 * @property string $goods_id
 * @property string $path
 */
class GoodsGallery extends \yii\db\ActiveRecord
{

    public $uploadAlbum;
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'goods_gallery';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['goods_id'], 'integer'],
            [['path'], 'string', 'max' => 255],
            [['uploadAlbum'],'image','maxFiles'=>5],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'goods_id' => '商品ID',
            'path' => '商品相册图片',
            'uploadAlbum' => '商品相册图片',
        ];
    }

     public function galleryUrl(){
        $galleryPath =$this->path;
        if(substr($galleryPath,0,4)=='http'){
            return $galleryPath;
        }elseif(empty($galleryPath)){
            return $galleryPath;
        }else{
            return Yii::$app->params['imgUrl'].$galleryPath;
        }
    }
}
